home *** CD-ROM | disk | FTP | other *** search
- Path: in-news.erinet.com!usenet
- From: timb@erinet.com (Tim Berens)
- Newsgroups: comp.lang.c
- Subject: Re: my program has a mind of its own (no really)
- Date: Tue, 09 Apr 1996 21:12:02 GMT
- Organization: EriNet Online 513 436-9915
- Message-ID: <4ke9d2$eqp@eri.erinet.com>
- References: <sbb-0904960305370001@ts13-06.upenn.edu>
- NNTP-Posting-Host: dlp3.ctrvl.eri.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- sbb@eniac.seas.upenn.edu (Steve Bronstein) wrote:
-
- >I am writing a program (with cc as compiler) which has a number of arrays,
- >which I have been verry careful to initialize with values, to avoid
- >segmentation faults. The main part of the program is a loop beginning with
- >an fgets statement to read in the next line from a file. Under certain
- >circumstances, the program returns "Segmentation Fault" just as it reaches
- >the beginning of this loop. When I put it a printf statement right before
- >the loop to see how far it actually got, it worked.
-
- >printf("something\n");
-
- >When I removed "something", leaving just
-
- >printf("\n");
-
- >it gave me a segmentation fault again. I tried the same tactic at the
- >beginning of the loop, and found that the program worked with a long word
- >in the printf statement, but not a short word. Needless to say, I am
- >slightly bewildered by this behavior, as the printf statement, at least to
- >my knowledge, has no effect on my arrrays. If anyone has had a similar
- >experience, or knows what's going on here, I'd be extremely grateful.
-
- >Thanks,
-
- >Steve Bronstein
- >http://www.seas.upenn.edu/~sbb
-
- There's a commercial product called memcheck which can be invaluable
- in tracking down this type of problem. I had a nasty little problem
- that was in a system I was developing. It was buried somewhere in
- about 50,000 lines of code, and occasionally caused UNIX to dump core.
- Classic pointer problem symptoms.
-
- Since I was on a very tight deadline and knew how long this kind of
- problem can take to track down, I ordered memcheck. It took about an
- hour to install and get it compiled into my code. It pointed me to
- the exact line of code causing the problem the first time I ran the
- program. No joke. I know I sound like somebody on the Home Shopping
- Network, but it really worked wonders. I never fly without it now.
-
- Disclaimer: I have no connection to the company that makes memcheck.
- If you are interested in the product, look up their ads in Dr. Dobb's
- or C User's Journal. The company name is StratosWare.
-
- Tim Berens
-
-